package com.anlogic.sdk.ui;

import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;

import com.anlogic.sdk.utils.ProjectUtils;

public class ResourceDeletableTester extends PropertyTester {
	@Override
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
        if ("deletable".equals(property)) {
        	if (receiver instanceof IResource) {
                IProject project = ((IResource) receiver).getProject();
                return !ProjectUtils.isDebugging(project);
        	} else if (receiver instanceof ITranslationUnit) {
        		IProject project = ((ITranslationUnit)receiver).getCProject().getProject();
        		return !ProjectUtils.isDebugging(project);
        	} else if (receiver instanceof IBinary) {
        		IProject project = ((IBinary)receiver).getCProject().getProject();
        		return !ProjectUtils.isDebugging(project);
        	} else if (receiver instanceof IArchive) {
        		IProject project = ((IArchive)receiver).getCProject().getProject();
        		return !ProjectUtils.isDebugging(project);
        	} else if (receiver instanceof ISourceRoot) {
        		IProject project = ((ISourceRoot)receiver).getCProject().getProject();
        		return !ProjectUtils.isDebugging(project);
        	} else if (receiver instanceof ICContainer) {
        		IProject project = ((ICContainer)receiver).getCProject().getProject();
        		return !ProjectUtils.isDebugging(project);
        	}
        }
        return true;
    }
}